//
//  NearNet.m
//  SportSocial
//
//  Created by yull on 15/1/3.
//  Copyright (c) 2015年 yull. All rights reserved.
//

#import "NearNet.h"

@implementation NearNet

+ (AFHTTPRequestOperation *)nearUserWithLatitude:(CGFloat)latitude
                                   longitude:(CGFloat)longitude
                                   precision:(NSInteger)precision
                                successBlock:(httpSuccessBlock)successBlock
                                   failBlock:(httpFailBlock)failBlock
{
    NSString *url = [[NSString alloc] initWithFormat:@"%@/user/near",[self baseUrl]];
    
    NSDictionary *param = @{@"token":[self token],
                            @"latitude":[NSNumber numberWithFloat:latitude],
                            @"longitude":[NSNumber numberWithFloat:longitude],
                            @"precision":[NSNumber numberWithInt:precision]};
    
    AFHTTPRequestOperation *operation = [[self manager] GET:url parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        successBlock (operation,responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failBlock (operation,error);
    }];
    return operation;
}

+ (AFHTTPRequestOperation *)nearPlaceWithLatitude:(CGFloat)latitude
                                        longitude:(CGFloat)longitude
                                        precision:(NSInteger)precision
                                     successBlock:(httpSuccessBlock)successBlock
                                        failBlock:(httpFailBlock)failBlock
{
    NSString *url = [[NSString alloc] initWithFormat:@"%@/place/near",[self baseUrl]];
    
    NSDictionary *param = @{@"token":[self token],
                            @"latitude":[NSNumber numberWithFloat:latitude],
                            @"longitude":[NSNumber numberWithFloat:longitude],
                            @"precision":[NSNumber numberWithInt:precision]};
    
    AFHTTPRequestOperation *operation = [[self manager] GET:url parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        successBlock (operation,responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failBlock (operation,error);
    }];
    return operation;
}

+ (AFHTTPRequestOperation *)nearGroupWithLatitude:(CGFloat)latitude
                                        longitude:(CGFloat)longitude
                                        precision:(NSInteger)precision
                                     successBlock:(httpSuccessBlock)successBlock failBlock:(httpFailBlock)failBlock
{
    NSString *url = [[NSString alloc] initWithFormat:@"%@/group/near",[self baseUrl]];
    
    NSDictionary *param = @{@"token":[self token],
                            @"latitude":[NSNumber numberWithFloat:latitude],
                            @"longitude":[NSNumber numberWithFloat:longitude],
                            @"precision":[NSNumber numberWithInt:precision]};
    
    AFHTTPRequestOperation *operation = [[self manager] GET:url parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        successBlock (operation,responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failBlock (operation,error);
    }];
    return operation;
}
@end
